<div class="layui-fluid layui-anim website-anim-up" id="website-class-apply-update" lay-title="年度课题修改">
    <div class="layui-row layui-col-space8 website-container">
        <div class="layui-col-md10 layui-col-sm10 layui-col-xs10">
            <form class="layui-form" id="class-apply-update-form">
                <div class="layui-card" id="client-user-info">
                    <div class="layui-card-header">基本情况</div>
                    <div class="layui-card-body layui-form-item">
                        <div class="layui-row">
                            <!-- 基本信息-->
                            <div class="layui-form-item website-hide">
                                <label class="layui-form-label">id：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="declareId" data-th-value="${result.declareId}">
                                </div>
                            </div>
                            <div class="layui-form-item website-hide">
                                <label class="layui-form-label">leaderid：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.applicantId"
                                           data-th-value="${result.leader.applicantId}">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">课题名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" autocomplete="off" lay-verify="required"
                                           maxlength="50"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label id="levelTypeCodeLabel"
                                       class="layui-form-label website-form-item-require">申报级别</label>
                                <div class="layui-input-inline">
                                    <select id="firstLevelTypeCode" name="firstLevelTypeCode" lay-verify="required"
                                            lay-filter="firstLevelTypeCode">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                                <label></label>
                                <div class="layui-input-inline">
                                    <select name="levelTypeCode" id="levelTypeCode" lay-verify="required">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>

                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">成果形式</label>
                                <div class="layui-input-block">
                                    <select name="achievementFormTypeCode"
                                            lay-verify="required"
                                            xm-select-direction="down"
                                            xm-select="achievementFormTypeCode"
                                            xm-select-skin="default">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${achievementForm}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">成果字数</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="achievementFormSize" autocomplete="off"
                                           lay-verify="required" maxlength="50"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">万字</div>
                            </div>
                        </div>
                        <div class="layui-row ">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">申报年份</label>
                                <div class="layui-input-block">
                                    <input type="text" id="applyYear" name="year" autocomplete="off"
                                           lay-verify="required"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">课题编号</label>
                                <div class="layui-input-block">
                                    <select name="topicId" lay-verify="required" id="topicId" lay-filter="topicId">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${topics}"
                                                th:value="${item.topicId}" th:text="${item.topicName}">
                                        </option>
                                    </select>
                                </div>
                            </div>

                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">主持人姓名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.name" autocomplete="off" lay-verify="required"
                                           maxlength="50"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require"> 学科分类</label>
                                <div class="layui-input-block">
                                    <select name="subjectTypeCode" lay-verify="required" lay-filter="subjectTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${subjectTypeCode}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">行政职务</label>
                                <div class="layui-input-block">
                                    <select name="leader.positionTypeCode" lay-verify="required"
                                            lay-filter="positionTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${positionTypeCode}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">职称级别</label>
                                <div class="layui-input-block">
                                    <select name="leader.titleTypeCode" lay-verify="required"
                                            lay-filter="titleTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${titleTypeCode}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row ">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">职称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.professionCode" maxlength="50" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">工作单位</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.company" lay-verify="required" autocomplete="off"
                                           maxlength="50"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6">
                                <label class="layui-form-label ">人事关系所在地</label>
                                <div class="layui-input-block">
                                    <select name="leader.personnelAreaTypeCode" lay-filter="personnelAreaTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${personnelAreaType}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6">
                                <label class="layui-form-label website-form-item-require">出生日期</label>
                                <div class="layui-input-block">
                                    <input type="text" lay-verify="required" id="birthday" name="leader.birthday"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label ">性别</label>
                                <div class="layui-input-block">
                                    <select name="leader.sexTypeCode" lay-filter="sexTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${sex}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label layui-form-label">民族</label>
                                <div class="layui-input-block">
                                    <select name="leader.nationTypeCode"
                                            lay-filter="nationTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${nation}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">证件类型</label>
                                <div class="layui-input-block">
                                    <select id="identityTypeCode" name="leader.identityTypeCode" lay-filter="identityTypeCode"
                                            lay-verify="required">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${identityTypeCode}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">证件号码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.identity" lay-verify="required"
                                           autocomplete="off" maxlength="50" id="identity"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">研究类型</label>
                                <div class="layui-input-block">
                                    <select name="researchTypeCode" lay-verify="required" lay-filter="researchTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${research}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label layui-form-label">政治面貌</label>
                                <div class="layui-input-block">
                                    <select name="leader.politicalTypeCode"
                                            lay-filter="politicalTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${political}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label layui-form-label">外语语种</label>
                                <div class="layui-input-block">
                                    <select name="leader.language" lay-filter="language">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${language}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">最终学位</label>
                                <div class="layui-input-block">
                                    <select name="leader.degreeTypeCode" lay-verify="required"
                                            lay-filter="degreeTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${degree}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label">担任导师</label>
                                <div class="layui-input-block">
                                    <select name="leader.tutorTypeCode" lay-filter="tutorTypeCode">
                                        <option value="">请选择</option>
                                        <option
                                                th:each="item : ${tutor}"
                                                th:value="${item.code}" th:text="${item.name}">
                                        </option>
                                    </select>
                                </div>
                            </div>
                        </div>


                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">通讯地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.address" lay-verify="required" autocomplete="off"
                                           maxlength="50"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">邮政编码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.postCode" lay-verify="required|number"
                                           autocomplete="off" maxlength="50"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">电子邮箱</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.email" lay-verify="required|email"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label">座机</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.telephone" lay-verify="tellphone" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">手机</label>
                                <div class="layui-input-block">
                                    <input type="text" name="leader.mobile" lay-verify="required|phone"
                                           autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row more-add">
                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">显名附件</label>
                                <a id="upload-file-a"></a>
                                <button type="button" class="layui-btn" id="upload-file">
                                    <i class="layui-icon">&#xe67c;</i>上传显名附件
                                </button>
                            </div>

                            <div class="layui-inline layui-col-xs6 layui-col-sm6 layui-col-md6 ">
                                <label class="layui-form-label website-form-item-require">匿名附件</label>
                                <a id="upload-file-anonymous-a"></a>
                                <button type="button" class="layui-btn" id="upload-file-anonymous">
                                    <i class="layui-icon">&#xe67c;</i>上传匿名附件
                                </button>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md12">
                                <label class="layui-form-label layui-form-label">主要观点</label>
                                <div class="layui-input-block">
                                <textarea class="layui-textarea" name="mainPoint" placeholder="请输入内容，限制 500 字"
                                          maxlength="500"
                                          autocomplete="off"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card more-add" id="client-class-member">
                    <div class="layui-card-header">课题组人员</div>
                    <div class="layui-card-body website-table-full">
                        <div class="layui-row">
                            <div class="layui-col-md-offset11 layui-col-md1">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-add-member">
                                    新增课题组成员
                                </div>
                            </div>
                        </div>
                        <table id="classApplyMemberTable" lay-filter="classApplyMemberTable"
                               lay-data="{id: 'classApplyMemberTable'}"></table>
                    </div>
                </div>
                <div class="layui-card more-add" id="client-class-project-info">
                    <div class="layui-card-header">主持人曾经主持省部级以上社科研究项目及完成情况</div>
                    <div class="layui-card-body website-table-full">
                        <div class="layui-row">
                            <div class="layui-col-md-offset11 layui-col-md1">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-add-project-info">
                                    新增信息
                                </div>
                            </div>
                        </div>
                        <table lay-filter="classApplyProjectInfoTable" id="classApplyProjectInfoTable"
                               lay-data="{id: 'classApplyProjectInfoTable'}"></table>
                    </div>
                </div>
                <!--         研究基础和研究条件       -->
                <div class="layui-card more-add">
                    <div class="layui-card-header">研究基础和研究条件</div>
                    <div class="layui-card-body">
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs12 layui-col-sm12 layui-col-md12">
                                <span class="website-form-item-require">主持人近5年发表、出版的相关研究成果（注明刊物的年、期或出版社、出版日期）</span>
                                <textarea class="layui-textarea" name="leaderWorks5" placeholder="请输入内容"
                                          lay-verify="required" maxlength="1000"
                                          autocomplete="off"></textarea>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs12 layui-col-sm12 layui-col-md12">
                                <span class="website-form-item-require">课题组成员近3年发表、出版的与本课题有关的主要研究成果（注明刊物的年、期或出版社、出版日期）</span>

                                <textarea class="layui-textarea" placeholder="请输入内容" name="memberWorks3"
                                          lay-verify="required" maxlength="1000"
                                          autocomplete="off"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 研究内容-->
                <div class="layui-card more-add" id="client-class-Solicit">
                    <div class="layui-card-header website-form-item-require">研究内容</div>
                    <div class="layui-card-body">
                        <div class="layui-row">
                            <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md12">
                                <span>内容包括:
                                    （1）研究的主要内容、主要观点、主要创新，解决的问题或提出的主要对策建议及论证理由(不少于3000字) ;
                                    （2）是否开展调研、调研方式及主要成果;
                                    （3）研究情况的自我评估，成果的理论价值、实践价值，需要完善之处，下一步研究计划。</span>
                                <textarea class="layui-textarea" name="researchContent" placeholder="请输入内容"
                                          lay-verify="required" maxlength="5000"
                                          autocomplete="off"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-footer">
                    <button class="layui-btn more-add" lay-submit="" lay-filter="class-apply-update-form-submit"
                            id="submit">课题申请
                    </button>
                    <button class="layui-btn" lay-submit="" lay-filter="class-apply-update-form-save" id="save">保存
                    </button>
                    <button class="layui-btn" id="reset">返回</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--成员表-->
<!--成员表操作栏-->
<script type="text/html" id="member-option">
    <a lay-event="edit" class="website-blue">修改</a>
    <a lay-event="del" class="website-red">删除</a>
</script>
<!--主持人表-->
<!--主持人表操作栏-->
<script type="text/html" id="project-option">
    <a lay-event="edit" class="website-blue">修改</a>
    <a lay-event="del" class="website-red">删除</a>
</script>


<script type="text/html" id="sex-type">
    {{#
    let dict=layui.dict.getByCode(d.sexTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="position-type">
    {{#
    let dict=layui.dict.getByCode(d.positionTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="title-type">
    {{#
    let dict=layui.dict.getByCode(d.titleTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="degree-type">
    {{#
    let dict=layui.dict.getByCode(d.degreeTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="finish-type">
    {{#  if(d.isFinish.toString() === 'true'){ }}
    <span>是</span>
    {{#  }else{ }}
    <span>否</span>
    {{#  } }}
</script>
<script type="text/html" id="identity-type">
    {{#
    let dict=layui.dict.getByCode(d.identityTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>

<script data-th-inline="javascript" type="text/javascript">
    layui.use(['jquery', 'laydate', 'form', 'table', 'website', 'upload', 'dict', 'formSelects', 'validate', 'clientModules'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            website = layui.website,
            form = layui.form,
            formSelects = layui.formSelects,
            table = layui.table,
            validate = layui.validate,
            upload = layui.upload,
            client = layui.clientModules,

            $view = $('#website-class-apply-update'),
            $form = $('#class-apply-update-form'),
            $submit = $('#submit'),
            $reset = $('#reset'),
            $save = $('#save'),
            $projectView = $('#client-class-project-info'),
            $memberView = $('#client-class-member'),
            $addProject = $projectView.find('.action-add-project-info'),
            $addMember = $memberView.find('.action-add-member'),
            $topicId = $('#topicId'),

            result = [[${result}]],
            classType = [[${classType}]],
            businessType = [[${businessType}]],
            groups = [[${level}]],
            statusTypeCode = result.statusTypeCode,

            memberTableIns,
            projectInfoTableIns,
            uploadFile,
            uploadFileAnonymous,
            showMore,
            deleteMemberIds = [],
            deleteProjectIds = []
        ;
        initForm();
        // 重新渲染 form否则不会显示下拉框
        formSelects.render();

        form.render();
        initExpertValue();
        initMemberTable();
        initProjectInfoTable();


        form.verify(validate);

        //初始化年份的搜索框
        laydate.render({
            elem: '#applyYear', //指定元素
            type: 'year',
            trigger: 'click',
            done: function (value, date, endDate) {
                date.topicClassifyCode = classType
                website.get(ctx + 'topics/declare', date, function (data) {
                    // 清空下拉框
                    $topicId.empty()
                    let result = data.data,
                        html = '<option value="">请选择</option>\n';
                    $.each(result, function (i, item) {
                        html += '<option value="' + item.topicId + '">' + item.topicName + '</option>\n'
                    })
                    $topicId.append(html);
                    //从新刷新了一下下拉框
                    form.render('select');
                });
                let config = layui.dict.getBusinessType(date.year)
                initForm(config)
                if (!config.isTopicLev) {
                    client.removeVerify([Label = $("#levelTypeCodeLabel")],
                        [levelTypeCode = $("#levelTypeCode")[0], firstLevelTypeCodeBox = $("#firstLevelTypeCode")[0]])
                }
            }
        });

        laydate.render({
            //
            elem: '#birthday', //指定元素
            type: 'date',
            max: 0 //7天后
        })

        function initForm(config) {
            if (!config) {
                config = layui.dict.getBusinessType(result.year)
            }
            showMore = statusTypeCode === 'pre_apply' || (config.businessType === '1' && statusTypeCode === 'no_apply');
            if (showMore) {
                $('.more-add').show()
            } else {
                $('.more-add').addClass('website-hide')
                $.each($("input:hidden"), function (i, value) {
                    value.setAttribute('lay-verify', '')
                })
                $.each($("textarea:hidden"), function (i, value) {
                    value.setAttribute('lay-verify', '')
                })
                $.each($("select:hidden"), function (i, value) {
                    value.setAttribute('lay-verify', '')
                })
            }
        }

        function initMemberTable() {
            website.get(ctx + result.declareId + '/memberInfo/list', null, function (data) {
                memberTableIns = website.table.init({
                    elem: $memberView.find('table'),
                    id: 'classApplyMemberTable',
                    data: data.data.list,
                    cols: [
                        [
                            {type: 'numbers', title: '序号'},
                            {field: 'name', title: '姓名', minWidth: 80},
                            {title: '性别', templet: '#sex-type'},
                            {field: 'birthday', title: '出生年月'},
                            {title: '职务', templet: '#position-type'},
                            {title: '职称级别', templet: '#title-type'},
                            {title: '职称', field: 'professionCode'},
                            {title: '最终学位', templet: '#degree-type'},
                            {field: 'field', title: '研究领域'},
                            {templet: '#identity-type', title: '证件类型'},
                            {field: 'identity', title: '证件号', minWidth: 145},
                            {field: 'companyAddress', title: '工作单位', minWidth: 160},
                            {field: 'mobile', title: '联系电话'},
                            {field: 'email', title: '电子邮箱'},
                            {title: '操作', toolbar: '#member-option', minWidth: 140}
                        ]
                    ],
                    page: false,
                    limit: Number.MAX_VALUE
                });
            });
        }

        table.on('tool(classApplyMemberTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                website.modal.confirm('删除成员', '确定删除该成员？', function () {
                    deleteMembers(obj);
                });
            }
            if (layEvent === 'edit') {
                // 修改
                client.openMember(obj, memberTableIns)
                // openMember(obj)
            }
        });

        // 选题征集新增按钮页面跳转
        $addMember.on('click', function () {
            client.openMember({}, memberTableIns)
        })


        function initProjectInfoTable() {
            website.get(ctx + result.declareId + '/leaderProject/list', null, function (data) {
                projectInfoTableIns = website.table.init({
                    elem: $projectView.find('table'),
                    id: 'classApplyProjectInfoTable',
                    data: data.data.list,
                    cols: [
                        [
                            {type: 'numbers', title: '序号'},
                            {field: 'projectSource', title: '项目来源', minWidth: 100},
                            {field: 'type', title: '类别'},
                            {field: 'topicName', title: '课题名称', minWidth: 200},
                            {field: 'projectTime', title: '立项时间', minWidth: 165},
                            {templet: '#finish-type', title: '是否结项'},
                            {title: '操作', toolbar: '#project-option', minWidth: 140}
                        ]
                    ],
                    page: false,
                    limit: Number.MAX_VALUE
                });
            });
        }

        table.on('tool(classApplyProjectInfoTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                website.modal.confirm('删除项目', '确定删除该项目？', function () {
                    deleteProjectInfos(obj);
                });
            }
            if (layEvent === 'edit') {
                // 修改
                client.openProject(obj, projectInfoTableIns)
            }
        });


        // 课题申报新增按钮页面跳转
        $addProject.on('click', function () {
            client.openProject({}, projectInfoTableIns)
        })


        uploadFile = upload.render({
            elem: '#upload-file' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code === 200) {
                    website.alert.success('上传文件成功');
                    let data = res.data
                    $('#upload-file-a')[0].setAttribute('file-id', data.fileId)
                    $('#upload-file-a')[0].setAttribute('href', ctx + 'download/' + data.fileId)
                    $("#upload-file-a").text(data.name)
                }
            }
            , error: function () {
                //请求异常回调
                website.alert.error('上传文件失败');
            },
            accept: 'file',
            size: 1024 * 50
        });

        uploadFileAnonymous = upload.render({
            elem: '#upload-file-anonymous' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code === 200) {
                    website.alert.success('上传文件成功');
                    let data = res.data
                    $('#upload-file-anonymous-a')[0].setAttribute('file-id', data.fileId)
                    $("#upload-file-anonymous-a")[0].setAttribute('href', ctx + 'download/' + data.fileId)
                    $("#upload-file-anonymous-a").text(data.name)
                }
            }
            , error: function () {
                //请求异常回调
                website.alert.error('上传文件失败');
            },
            accept: 'file',
            size: 1024 * 50
        });


        function getParams() {
            let temp = $form.serializeArray(),
                formData = website.serializeObject(temp);
            // 2. 成员表序列化
            formData.memberInfos = table.cache["classApplyMemberTable"]
            // 3. 项目表序列化
            formData.leaderProjects = table.cache["classApplyProjectInfoTable"];
            formData.deleteMemberIds = deleteMemberIds
            formData.deleteProjectIds = deleteProjectIds
            formData.normalFileId = $('#upload-file-a')[0].getAttribute('file-id')
            formData.anonymousFileId = $("#upload-file-anonymous-a")[0].getAttribute('file-id')
            // let params = JSON.stringify(formData)
            return formData
        }

        //    提交表单
        form.on('submit(class-apply-update-form-submit)', function () {
            classApplyOpen()
            return false;
        });

        function classApplyOpen() {
            website.modal.open('申请人承诺书', 'client/classApplyCommitment', {
                btn: ['提交', '取消'],
                area: $(window).width() <= 750 ? '95%' : '50%',
                offset: '30px',
                yes: function (index, layero) {
                    // 1. 当前页表单
                    let params = getParams()
                    if (showMore) {
                        if (!params.normalFileId || !params.anonymousFileId) {
                            website.alert.error('请上传文件');
                            return false
                        }
                    }
                    website.ajaxPost(ctx + 'declareTopic/update', JSON.stringify(params), function () {
                        // 申请详情
                        website.post(ctx + 'declareTopic/' + params.declareId + '/commit', null, function (data) {
                            //  关闭当前页面
                            $('#website-home').find('#query').click();
                            let currentUrl = window.location.hash.replace('#', '');
                            website.view.tab.del(currentUrl);
                            window.location.reload();
                            layer.closeAll()
                        });
                    });
                },
                btn2: function () {
                    layer.closeAll()
                }
            });
        }


        //    保存表单
        form.on('submit(class-apply-update-form-save)', function () {
            // 1. 当前页表单
            let params = getParams()
            if (showMore) {
                if (!params.normalFileId || !params.anonymousFileId) {
                    website.alert.error('请上传文件');
                    return false
                }
            }
            let tempParams = JSON.stringify(params)
            website.ajaxPost(ctx + 'declareTopic/update', tempParams, function () {
                //  关闭当前页面
                $('#website-home').find('#query').click();
                let currentUrl = window.location.hash.replace('#', '');
                website.view.tab.del(currentUrl);
                window.location.reload();
            });
            return false;
        });

        function deleteMembers(obj) {
            let data = obj.data
            let memberId = data.memberId
            if (memberId) {
                //  编辑页面，需要根据 ID删除
                deleteMemberIds.push(memberId)
            }
            // 从缓存中删除
            let cacheData = table.cache["classApplyMemberTable"];
            cacheData.splice(obj.tr.data('index'), 1)//根据索引删除当前行
            memberTableIns.reload({
                data: cacheData
            });

        }

        function deleteProjectInfos(obj) {
            let data = obj.data,
                projectId = data.projectId
            if (projectId) {
                //  编辑页面，需要根据 ID删除 projectId
                deleteProjectIds.push(projectId)
            }
            // 从缓存中删除
            let cacheData = table.cache["classApplyProjectInfoTable"];
            cacheData.splice(obj.tr.data('index'), 1)//根据索引删除当前行
            projectInfoTableIns.reload({
                data: cacheData
            });
        }


        form.on('select(firstLevelTypeCode)', function (data) {
            let tmp = data.value;
            $("#levelTypeCode").empty();
            $.each(groups, function (k, v) {
                if (v.type.code == tmp) {
                    if (v.course.length != 0) {
                        $.each(v.course, function (key, value) {
                            $("#levelTypeCode").append("<option value='" + value.code + "'>" + value.name + "</option>");
                        });
                    } else {
                        $("#levelTypeCode").append("<option value=''>" + '无内容' + "</option>");
                    }

                }
            });
            let defulValue = $("#levelTypeCode").val();
            if (defulValue == '') {
                $("#levelTypeValue").val(tmp);
            } else {
                $("#levelTypeValue").val(defulValue);
            }
            form.render();
        })


        function initExpertValue() {
            const formName = 'class-apply-update-form-' + result.declareId
            $('#class-apply-update-form')[0].setAttribute('lay-filter', formName);
            let config = layui.dict.getBusinessType(result.year)
            if (!config.isTopicLev) {
                client.removeVerify([Label = $("#levelTypeCodeLabel")],
                    [levelTypeCode = $("#levelTypeCode")[0], firstLevelTypeCodeBox = $("#firstLevelTypeCode")[0]])
            }
            let firstLevelTypeCode = '';
            $.each(groups, function (k, v) {
                $("#firstLevelTypeCode").append("<option value='" + v.type.code + "'>" + v.type.name + "</option>");
                $.each(v.course, function (key, value) {
                    if (firstLevelTypeCode === '' && value.code === result.levelTypeCode) {
                        //拿到父级的 code
                        if (v.type.dictId === Number(value.pid)) {
                            firstLevelTypeCode = v.type.code
                        }
                    }
                });
                if (firstLevelTypeCode === v.type.code) {
                    $.each(v.course, function (key, value) {
                        //拿到父级的 code
                        $("#levelTypeCode").append("<option value='" + value.code + "'>" + value.name + "</option>");
                    });
                }
            });
            debugger
            form.val(formName, {
                "id": result.declareId,
                "name": result.name,
                "year": result.year,
                "topicId": result.topicId,
                "firstLevelTypeCode": firstLevelTypeCode,
                "levelTypeCode": result.levelTypeCode,
                "subjectTypeCode": result.subjectTypeCode,
                "achievementFormSize": result.achievementFormSize,
                "leader.personnelAreaTypeCode": result.leader.personnelAreaTypeCode,
                "leader.identityTypeCode": result.leader.identityTypeCode,
                "leader.birthday": result.leader.birthday,
                "leader.name": result.leader.name,
                "leader.positionTypeCode": result.leader.positionTypeCode,
                "leader.titleTypeCode": result.leader.titleTypeCode,
                "leader.sexTypeCode": result.leader.sexTypeCode,
                "leader.nationTypeCode": result.leader.nationTypeCode,
                "leader.identity": result.leader.identity,
                "researchTypeCode": result.researchTypeCode,
                "leader.politicalTypeCode": result.leader.politicalTypeCode,
                "leader.degreeTypeCode": result.leader.degreeTypeCode,
                "leader.tutorTypeCode": result.leader.tutorTypeCode,
                "titleTypeCode": result.titleTypeCode,
                "degreeTypeCode": result.degreeTypeCode,
                "leader.language": result.leader.language,
                "leader.email": result.leader.email,
                "leader.company": result.leader.company,
                "leader.professionCode": result.leader.professionCode,
                "leader.address": result.leader.address,
                "leader.postCode": result.leader.postCode,
                "leader.telephone": result.leader.telephone,
                "leader.mobile": result.leader.mobile,
                "mainPoint": result.mainPoint,
                "leaderWorks5": result.leaderWorks5,
                "memberWorks3": result.memberWorks3,
                "researchContent": result.researchContent
            });
            formSelects.value('achievementFormTypeCode', result.achievementFormTypeCode.split(','));
            if ("zjlx_sfz" === result.leader.identityTypeCode) {
                $('#identity')[0].setAttribute('lay-verify', "required|identity")
            }else if (result.leader.identityTypeCode){
                $('#identity')[0].setAttribute('lay-verify', "required")
            }
            // 文件上传
            if (result.normalFileId) {
                $("#upload-file-a").text('点击下载');
                $("#upload-file-a")[0].setAttribute('href', ctx + 'download/' + result.anonymousFileId)
                $("#upload-file-a")[0].setAttribute('file-id', result.anonymousFileId)
            } else {
                $("#upload-file-a").text('无附件');
            }
            if (result.anonymousFileId) {
                $("#upload-file-anonymous-a").text('点击下载');
                $('#upload-file-anonymous-a')[0].setAttribute('file-id', result.normalFileId)
                $("#upload-file-anonymous-a")[0].setAttribute('href', ctx + 'download/' + result.normalFileId)
            } else {
                $("#upload-file-anonymous-a").text('无附件');
            }
        }

        $reset.on('click', function () {
            //  关闭当前页面
            $('#website-home').find('#query-entrust').click();
            let currentUrl = window.location.hash.replace('#', '');
            website.view.tab.del(currentUrl);
            window.location.reload();
        })

        form.on('select(identityTypeCode)', function (data) {
            if ("zjlx_sfz" === data.value) {
                // lay-verify="required|identity"
                $('#identity')[0].setAttribute('lay-verify', "required|identity")
            }else if (data.value){
                $('#identity')[0].setAttribute('lay-verify', "required")
            }
        });
    });
</script>